<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
    <BaseDialog :visible.sync="selectDelearFlag" :title="'服务中心选择'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DealerFrom @close="Delearclose" @save="Delearsave" selectionType="multiple"></DealerFrom>
    </BaseDialog>
      <!-- table -->
      <FormPanel ref="formPanel" :list="formList" :cols="2" :formType="'add'" labelWidth="100" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <div style="padding-top: 0.5rem;"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" :click="saveDialog.bind()">分 派</multiuse-button>
        <multiuse-button @click="closeDialog">取 消</multiuse-button>
      </div>
    </Spin>
  </div>
</template>

<script>
import { updateState } from '@/api/serviceass/batteryAlarm/batteryAlarmManage';
import DealerFrom from './DealerFrom.vue';
  export default {
    name: "index",
    components: {
      DealerFrom
    },
    props: {
      formData: {
        type: Object,
        default: () => ({})
      }
  },
    data() {
      return {
        fetchParams: {}, //ipa 接口
        formList: this.createFormList(),
        saveData: null,
        createdBy:'',
        loading: false,
        selectDelearFlag: false,
        dealerCode: {},
        rowData: {},
        dealerCompanyCode: '',
        dealerCode: ''
      }
    },
    methods: {
      async saveDialog() {
        if(this.dealerCode === ''){
          this.$notify.error({ type: '提示信息', message: '当前需要选择服务中心' });
          return;
        }
        this.rowData.bwId = this.formData.bwId;
        this.rowData.state = 55661002;
        this.rowData.remark = this.formList.find(x=>x.fieldName=='remark').initialValue;
        this.rowData.companyCode = this.dealerCompanyCode;
        this.rowData.dealerCode = this.dealerCode;
        let res = await updateState(this.rowData);
        if (res.resultCode === 200) {
          this.$emit('close');
          return this.$notify.success({title: '提示信息', message: '分派成功'});
        } else {
          this.loading = false;
        }
        this.loading = true;
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams = val;
      },
      //取消操作
      closeDialog(type) {
          this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      createFormList() {
        return [
          {
            type: 'TEXT_AREA',
            label: '备注',
            fieldName: 'remark',
            initialValue: '',
            placeholder: '',
            selfCols: 2
          },
          {
            type: 'INPUT',
            label: '服务中心代码',
            selfCols: 1,
            render: (p) => {
              return (
                <div>
                  <el-select v-model={this.dealerCode} disabled={true} placeholder="请选择"/>
                  <multiuse-button style="position: absolute;right: 0;height:100%" icon="el-icon-search" onClick={() => this.selectDelearFlag = true} />
                </div>
              );
            },
          },
          {
            type: 'INPUT',
            label: '服务中心简称',
            fieldName: 'dealerShortname',
            initialValue: '',
            selfCols: 1,
            disabled: true
          },
        ];
      },
        SelectDelear() {
          this.selectDelearFlag = true;
        }, 
        //关闭
        Delearclose() {
          this.selectDelearFlag = false;
        },
        //保存
        Delearsave(obj) {
          console.log('选择数据传递', obj);
          this.dealerCode = obj[0].dealerCode;
          this.dealerCompanyCode = obj[0].dealerCompanyCode;
          this.dealerCode = obj[0].dealerCode;
          this.formList.find(x=>x.fieldName=='dealerShortname').initialValue=obj[0].dealerShortname;
          this.selectDelearFlag = false;
        },
        formChangeHandle(val) {
          this.saveData = _.cloneDeep(val);
        },
    }
  }
</script>

<style scoped>

</style>
